package cn.itsource.pethome.org.controller;


import cn.itsource.pethome.base.domain.AjaxResult;
import cn.itsource.pethome.base.domain.ImgResult;
import cn.itsource.pethome.base.util.FastdfsUtils;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/file")
@Api(value = "文件上传的controller",description = "文件上传的的接口文档")
public class FileController {
    @Autowired
    FastdfsUtils fastdfsUtils;

    //http://47.95.117.210:8888/M00/02/AC/rBE3kWIV4NaAUrdpAACzXDSpsHE707.jpg
    @ApiOperation(value = "文件上传", notes = "文件上传")
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) throws IOException {
        StorePath upload = fastdfsUtils.upload(file);
        //个人猜测:这里是图片的路径
        String path = upload.getPath();
        String fullPath = upload.getFullPath();
        ImgResult imgResult = new ImgResult(fullPath, fullPath);
        AjaxResult ajaxResult = AjaxResult.me().setResult(imgResult);
        return ajaxResult;
    }

}
